<template>
  <div class="container" style="width:99%;margin-top:-25px;">
    <!-- 查询条件 -->
    <div class="query-box query-boxstudent">
      <el-form :model="queryBox" status-icon ref="queryBox">
  
       
        <el-row>
         
         
          <el-col :span="6">
            <div class="depart-box">
              <div class="slect-title">创建时间</div>
              <el-date-picker
                v-model="createDate"
                type="daterange"
                :start-placeholder="'开始时间'"
                :end-placeholder="'结束时间'"
                range-separator="至"
                :default-time="['00:00:00', '23:59:59']"
                value-format="yyyy-MM-dd HH:mm:ss"
                format="yyyy-MM-dd HH:mm:ss"
              ></el-date-picker>
            </div>
          </el-col>
         
        </el-row>
  
       
      
      </el-form>
      <div class="from-btns">
        <kt-button
          :label="$t('action.reset')"
          perms="true"
          type="primary"
          @click="reset('queryBox')"
        />
        <kt-button :label="$t('action.search')" type="primary" perms="true" @click="search"/>
      </div>
    </div>
    <!--表格内容栏-->
    <div class="btn">
      <Crm-table
        @selectionChange="selectionChange"
        class="table-width"
        noSignResource
        width="400"
        permsSee="customerstatistics:noSignResource:see"
        :data="pageResult"
        :columns="columns"
        :loading="loading"
        @findPage="findPage"
        @handleSee='handleSee'
      ></Crm-table>
    </div>
  </div>
</template>
<script>
import KtButton from "@/views/Core/KtButton";

import CrmTable from "@/views/Core/CrmTable";

import { CodeToText } from "element-china-area-data";
import { baseUrl } from "@/utils/global";
import axios from "axios";
import { regionDataPlus } from "element-china-area-data";
import { isMobile } from "@/utils/validate";
import Cookies from "js-cookie";
import store from "@/store";
export default {
  name: "Student",
  components: {
    CrmTable,
    KtButton,
  },
  data() {
    return {
      isShowFlag: 0, //0:初始化部门、人员不显示  1:部门显示 2：人员显示
      checkedPeson: 0,
      selectDisabled: false, //跟进弹窗客户进展状态
      typeDisabled: false,
      size: "medium",
      isLock: "",
      // filters: {
      //   name: ""
      // },
      // 查询条件
      student_data_from_options: [
        {
          label: " ",
          key: " "
        }
      ],
      student_type_options: [],
      student_progress_options: [
        {
          label: " ",
          key: " "
        }
      ],
      student_data_from_type_options: [
        {
          label: " ",
          key: " "
        }
      ],
      gradeCache: "",
      isopen: [
        {
          value: "解锁",
          label: "2"
        },
        {
          value: "锁定",
          label: "1"
        }
      ],
      student_import_department: [],
      queryBox: {
        name: "",
        dataFrom: "",
        type: "",
        dataFromType: "",
        progress: "",
        code: "",
        phone: "",
        school: "",
        providerTeacher: "",
        providerAgent: "",
        createDate: "",
        moveDate: "",
        belongToPerson: "",
        pageNum: 0,
        pageSize: 0,
        importDepartment: "",
        belongTo: "",
        phone: "",
        grade: "",
        equipment: "",
        source: "",
        pageAddress: "",
        keyWords: "",
        dataFromGroupKey:""
      },
      assignDate: "",
      gradeCache: "",
      width: 200,
      columns: [
        { type: "index", label: "序号", minWidth: 50 },
        // { prop: "importDepartment", label: "导入部门", minWidth: 100 },
        // { prop: "source", label: "推广来源", minWidth: 100 },
        { prop: "name", label: "学生姓名", minWidth: 120 },
        { prop: "phone", label: "联系电话", minWidth: 120 },
        {
          prop: "laiyuan",
          label: "客户来源",
          minWidth: 100,
          // id: "customerSource"
        },
        
        { prop: "type", label: "客户类型", minWidth: 100 },
        { prop: "belongTo", label: "所属销售", minWidth: 120 },
        { prop: "createDate", label: "创建时间", minWidth: 140 },
        {
          prop: "assignDate",
          sortable: "true",
          label: "最新分配时间",
          minWidth: 140
        },
        { prop: "trackingDate", label: "最新跟进时间", minWidth: 140 },
        { prop: "code", label: "客户编号", minWidth: 140 },
        // { prop: "trackingNum", label: "跟进次数", minWidth: 70 },
        // { prop: "getprogress", label: "客户进展", minWidth: 120 },
        // { prop: "source", label: "推广来源", minWidth: 100 },
        // { prop: "pageAddress", label: "页面地址", minWidth: 100 },
        // { prop: "keyWords", label: "分主题", minWidth: 100 },
        // { prop: "oemAccount", label: "OEM卡号", minWidth: 150 },
        // { prop: "oemType", label: "OEM卡类别", minWidth: 120 },
        // { prop: "school", label: "学校名称", minWidth: 120 },
        { prop: "diqu", label: "地区", minWidth: 190 },
       
        // { prop: "equipment", label: "设备", minWidth: 50 },
        // { prop: "providerTeacher", label: "所属教师", minWidth: 120 },
        // { prop: "providerAgent", label: "所属分中心", minWidth: 150 },
        // { prop: "code", label: "客户编号", minWidth: 150 }
      ],

    

      pageRequest: { pageNum: 1, pageSize: 10 },
      pageResult: {
        content: []
      },
      operation: true, // true:新增, false:编辑
      batchdistribution: false, //显示批量分配弹窗
      customerownership: false, //显示客户归属弹窗
      uploadOem: false, //文件上传
      limitNum: 1, //上传最大个数
      form: {
        file: ""
      },
      fileList: [],
      uploadUrl: baseUrl + "/file/upload", //文件上传地址
      downloadTmplUrl: baseUrl + "/template/studentImportTemplate.xlsx", //模板下载地址
      selectionsLength: "",
      deptTreeProps: {
        label: "name",
        children: "children"
      },
      roles: [],
      selections: [], //选中列表集合
      ids: [], //分配ID集合
      ids2: [],
      deptData: [], //部门树
      deptTree: {
        label: "deptName",
        children: "children"
      },
      deptinputValue: "",
      // 划分方式
      deptmodeoptions: [
        {
          label: "分配至部门",
          value: "11"
        },
        {
          label: "分配至个人",
          value: "9"
        }
      ],
      deptmodeoptionsValue: "",
      submitID: "",
      deptId: Cookies.get("threeLevelDeptId"),
      userID: "", //人员ID
      deptuseroption: [], //部门用户
      deptuseroptionValue: "",
      branchcenter: [], //分中心下拉
      branchcenterValue: "",
      branchcenterValueID: "",
      branchcenterCodeValue: "", //分中心编码
      addstuformData: {},
      branchCenterName: "",
      branchCenterNamePop: "", //归属分中心
      userName: "",
      createDate: "",
      trackingDate: "",
      oemType: "",
      AllotData: {
        belong_to_type: ""
      },
      grade_cache_gradeOptions: [],
      //   地区
      options: regionDataPlus,
      selectedOptions: [],
      loading: false, // 加载标识
      userDerpatName: "", //三级部门名称
      addFollow: false, //显示跟进窗口
      saveData: {
        customerType: "",
        contractDate: "",
        customerProgress: "",
        contractContent: "",
        nextContractDate: "",
        contactPeople: "",
        contractType: "",
        contractResult: "",
        studentId: this.$route.query.id,
        phoneAdress: "", //手机号码归属地
        source:"",
        importDepartment:'',
        sparePhoneAdress:'',
        grade:''
      },
      dates: new Date(),
      trackingPeople: Cookies.get("realName"),
      // 限制跟进时间
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7; //如果没有后面的-8.64e7就是不可以选择今天的
        }
      },
      student_communication_type: [],
      mytime: "",
      showBatchDelete: false,
      // 客户跟进数据
      stuqueryTrackingData: {
        content: []
      },
      pageRequest2: {
        pageNum: 1,
        pageSize: 10
      },
      demo: browserfly.noConflict(),
      student_result_options: [],
      callAdressUrl:
        "http://mobsec-dianhua.baidu.com/dianhua_api/open/location",
      student_equipmentgrade_options: [],
      student_TGsource_options: [],
      student_tracktype_options: [],
      student_progress_options2: [],
      subject_Options: [],
      comment:'',//备注
      roleId: "", //当前登录用户的角色id
      // roleId1: "307922416041209975", //咨询师
      // roleId2: "307922480151146627", //直销三级部门管理
      // roleId3: "307922544034590863", //直销部门管理
      // roleId4: "318843899038940998", //金丰和校区管理
      // roleId5: "318845886098849661", //金丰和班主任管理
      resources_Options:[],
      isSpareChange:false
    };
  },
  methods: {
    // 搜索
    search() {
      this.loading = true;
      this.queryBox.createDateStart = this.createDate[0];
      this.queryBox.createDateEnd = this.createDate[1];
      this.queryBox.trackingDateStart = this.trackingDate[0];
      this.queryBox.trackingDateEnd = this.trackingDate[1];
      this.queryBox.province = this.selectedOptions[0];
      this.queryBox.city = this.selectedOptions[1];
      this.queryBox.area = this.selectedOptions[2];
      this.pageRequest.pageNum = 1;
      if (this.assignDate != null) {
        this.queryBox.assignDateStart = this.assignDate[0];
        this.queryBox.assignDateEnd = this.assignDate[1];
      } else {
        this.queryBox.assignDateStart = "";
        this.queryBox.assignDateEnd = "";
      }

      this.findPage(null);
    },
    // 获取分页数据
    findPage: function(data) {
      if (data !== null) {
        this.loading = true;
        this.pageRequest = data.pageRequest;
      }
      this.queryBox.pageSize = this.pageRequest.pageSize;
      this.queryBox.pageNum = this.pageRequest.pageNum;

      this.$api.student
        .noSignResource(this.queryBox)
        .then(res => {
          if (res.result == 2) {
            this.$message({
              message: res.msg,
              type: "error"
            });
          } else {
            let content = {
              content: res.listStudentInfo,
              totalSize: res.total
            };
            this.pageResult = content;
            this.pageResult.content.forEach(item => {
              if (item.province == null || item.province == "null") {
                item.diqu = "";
              } else if (
                (item.province != null && item.city == null) ||
                (item.province != "null" && item.city == "null")
              ) {
                item.diqu = CodeToText[item.province];
              } else if (
                (item.province != null &&
                  item.city != null &&
                  item.area == null) ||
                (item.province != "null" &&
                  item.city != "null" &&
                  item.area == "null")
              ) {
                item.diqu = CodeToText[item.province] + CodeToText[item.city];
              } else if (
                (item.province != null &&
                  item.city != null &&
                  item.area != null) ||
                (item.province != "null" &&
                  item.city != "null" &&
                  item.area != "null")
              ) {
                item.diqu =
                  CodeToText[item.province] +
                  CodeToText[item.city] +
                  CodeToText[item.area];
              }
              // 客户来源对应
              this.student_data_from_options.forEach(type_item => {
                if (type_item.key == item.dataFrom) {
                  item.laiyuan = type_item.value;
                }
              });
              // 客户进展对应
              this.student_progress_options.forEach(progress_item => {
                if (progress_item.key == item.progress) {
                  item.getprogress = progress_item.value;
                }
              });
              // 获取方式对应
              this.student_data_from_type_options.forEach(
                data_from_type_item => {
                  if (data_from_type_item.key == item.dataFromType) {
                    item.getType = data_from_type_item.value;
                  }
                }
              ),
                // 客户类型
                this.student_type_options.forEach(student_type_item => {
                  if (student_type_item.key == item.type) {
                    item.type = student_type_item.value;
                    item.customerType = student_type_item.key;
                  }
                });
              // OEM卡类型
              this.oemType.forEach(oemItem => {
                if (oemItem.key == item.oemType) {
                  item.oemType = oemItem.value;
                }
              });
              //年级
              this.grade_cache_gradeOptions.forEach(gradeItem => {
                if (gradeItem.fId == item.grade) {
                  item.grade = gradeItem.fGradeName;
                }
              });
              // 转换推广设备
              this.student_equipmentgrade_options.forEach(equipmentItem => {
                if (equipmentItem.key == item.equipment) {
                  item.equipment = equipmentItem.value;
                }
              });
               //报告类型转义
            this.reportType_options.forEach(reportTypeItem => {
              if (reportTypeItem.key == item.reportType) {
                item.reportType2 = reportTypeItem.value;
              }
            });
            //报告结果转义
            this.reportResult_options.forEach(reportResultItem => {
              if (reportResultItem.key == item.reportResult) {
                item.reportResult = reportResultItem.value;
              }
            });
              // 学科
              this.studentSubject.forEach(subItem => {
                if (subItem.fId == item.subject) {
                  item.subject = subItem.fSpecialtyName;
                }
              });
             // 导入部门转换
            this.student_import_department.forEach(subItem => {
              if (subItem.key == item.importDepartment) {
                item.importDepartment = subItem.value;
              }
            });
            // 转换推广来源
              this.student_TGsource_options.forEach(TGsourceItem => {
                if (TGsourceItem.key == item.source) {
                  item.source = TGsourceItem.value;
                }
              });
              
            });
            this.loading = false;
          }
        })
        .then(data != null ? data.callback : "");
    },

    

    // 重置
    reset(queryBox) {
      this.$refs.queryBox.resetFields();
      this.createDate = "";
      this.queryBox.type = "";
      this.queryBox.dataFrom = "";
      this.queryBox.progress = "";
      this.queryBox.providerAgent = "";
      this.queryBox.dataFromType = "";
      this.queryBox.createDateStart = "";
      this.queryBox.createDateEnd = "";
      this.queryBox.trackingDateStart = "";
      this.queryBox.trackingDateEnd = "";
      this.queryBox.importDepartment = "";
      this.queryBox.isLock = "";
      this.queryBox.trackingNum = "";
      this.userName = "";
      this.branchCenterName = "";
      this.trackingDate = "";
      this.queryBox.belongTo = "";
      this.selectedOptions = [];
      this.queryBox.province = "";
      this.queryBox.city = "";
      this.queryBox.area = "";
      this.pageRequest.pageNum = 1;
      this.userDerpatName = "";
      this.queryBox.phone = "";
      this.queryBox.grade = "";
      this.queryBox.departmentId = "";
      this.queryBox.equipment = "";
      this.queryBox.source = "";
      this.queryBox.pageAddress = "";
      this.queryBox.keyWords = ""; //网推分主题查询
      this.assignDate = "";
      this.queryBox.assignDateStart = "";
      this.queryBox.assignDateEnd = "";
      this.queryBox.subject = "";
      this.queryBox.dataFromGroupKey=""
      this.findPage(null);
    },
    // 查看客户档案
    handleSee: function(params) {
      this.dataForm = Object.assign({}, params.row);
      // console.log(params.row)
      this.$router.push({
        path: "/Customerfile/Student",
        query: {
          id: this.dataForm.id
        }
      });
    },
    // 新增客户
    handleNewADD: function() {
      this.$router.push({
        path: "/Customerfile/AddStudent",
        query: {
          name: "customerManager"
        }
      });
    },
    selectionChange: function(params) {
      let selectionsLength = params.selections.length;
      this.selections = selections.selections;
    },
    // 获取选中的表格数据
    selectionChange: function(selections) {
      this.selections = selections.selections;
    },

    // 获取来源
    get_student_data_from() {
      this.student_data_from_options = JSON.parse(
        localStorage.getItem("studentSource")
      );
    },
    // 获取进展
    get_student_progress() {
      this.student_progress_options = JSON.parse(
        localStorage.getItem("studenProgress")
      );
    },
    student_progress_change(value) {
      this.queryBox.student_progressValue = value.toString();
    },
    // 获取OEM卡类型
    get_oemType() {
      this.oemType = JSON.parse(localStorage.getItem("oemType"));
    },
    // 获取导入部门
    get_student_importDepartment() {
      this.$api.user
        .optionsList({ codeType: "student_import_department" })
        .then(res => {
          this.student_import_department = res.keyValueList;
        });
    },
    
    
    // 客户类型
    get_student_type() {
      this.student_type_options = JSON.parse(
        localStorage.getItem("stdentTpye")
      );
    },
    // 获取方式
    get_student_data_from_type() {
      this.student_data_from_type_options = JSON.parse(
        localStorage.getItem("stdentDataFromType")
      );
      this.subject_Options = JSON.parse(
        localStorage.getItem("studentSubject")
      );
    },
    student_parent_type_change(value) {
      this.info.studentInfoDetail.studentInfoAttr.parentType = value.toString();
    },
    // 获取销售姓名
    get_sale_name() {
      this.$api.dropdown.users({ userType: 3 }).then(res => {
        this.belongTo = res.userInfoList;
      });
    },    
    // 获取年级
    get_grade_cache() {
      this.grade_cache_gradeOptions = JSON.parse(
        localStorage.getItem("gradeCache")
      );
    },
    gradeChange(item) {
      this.queryBox.grade = item.fId;
    },
    gradeChange2(item) {
      this.saveData.grade = item;
      // this.saveData.grade = item.fId;
    },
    studentEquipmentChange(item) {
      this.queryBox.equipment = item.key;
    },
    studentTGsourceChange(item) {
      this.queryBox.source = item.key;
    },
    // 获取网推的下拉选项
    get_TG_options() {
      this.student_equipmentgrade_options = JSON.parse(
        localStorage.getItem("studentEquipment")
      );
      this.student_TGsource_options = JSON.parse(
        localStorage.getItem("studentTGsource")
      );
    },
   

    

    // 沟通形式
    get_contractType() {
      this.student_communication_type = JSON.parse(
        localStorage.getItem("studentContractType")
      );
    },

    // 点击客户类型
    typeChange() {
      if (this.saveData.customerType == 5) {
        this.saveData.customerProgress = "8";
      }
    },

    // 点击客户进展
    progressChange() {
      if (this.saveData.customerProgress == 8) {
        this.saveData.customerType = "5";
      }
    },

    // 导出
    handleExport() {
      axios({
        method: "get",
        url: baseUrl + "/studentInfo/exportCustomerManager",
        params: this.queryBox
      }).then(res => {
        window.open(res.request.responseURL);
      });
    },

    
   

    // 获取沟通结果
    get_result() {
      this.student_result_options = JSON.parse(
        localStorage.getItem("progressResult")
      );
    },

    // 选择沟通结果
    contractResultChange() {
      if (this.saveData.contractResult != "") {
        // this.saveData.contractContent = "";
      }
    },


    // 获取沟通类型
    get_studentContractType() {
      this.studentContractType_options = JSON.parse(
        localStorage.getItem("studentContractType")
      );
    },
    // 获取跟进时候的客户进展
    get_track_progress() {
      this.student_progress_options2 = JSON.parse(
        localStorage.getItem("studenProgress2")
      );
    },
    // 获取跟进客户类型
    get_student_track_type() {
      this.student_tracktype_options = JSON.parse(
        localStorage.getItem("stdentTpye")
      );
    },
    // 获取分中心
    get_branchcenter() {
      this.$api.dropdown.branchcenter().then(res => {
        this.branchcenter = res.branchCenterInfoList;
      });
    },

    studentSubject() {
      this.studentSubject = JSON.parse(
        localStorage.getItem("studentSubject")
      );
    },
      // 报告类型
    get_reportType() {
      this.reportType_options = JSON.parse(
        localStorage.getItem("studentReportType")
      );
    },
    // 报告结果
    get_reportResult() {
      this.reportResult_options = JSON.parse(
        localStorage.getItem("studentReportResult")
      );
    },
  },  
  mounted() {
    this.get_student_data_from();
    this.get_student_progress();
    this.get_student_type();
    this.get_student_data_from_type();
    this.get_sale_name();
    this.get_oemType();
    this.get_student_importDepartment();
    this.get_grade_cache();
    this.get_contractType();
    this.get_result();

    this.get_studentContractType();
    this.get_TG_options();
    this.get_track_progress();
    this.get_student_track_type();
    this.get_branchcenter();
    this.studentSubject();
    this.get_reportType();
    this.get_reportResult();
  },
  destroyed: function() {
    this.demo.destroy();
  }
};
</script>

<style>
@import url("../../assets/queryBox.css");
</style>



